<?php

class PermissaoDAO {

    private $conexao_mysql = null;

    public function __construct() {
        $this->conexao_mysql = Conexao::getInstance();
    }

    public function insert($permissao) {
        $insert_sql = "INSERT INTO PERMISSAO (CRIAR, EDITAR, EXCLUIR, PUBLICAR, DESPUBLICAR) 
									VALUES ( ?, ?, ?, ?, ?);";
        try {

            $stmt = $this->conexao_mysql->prepare($insert_sql);

            $stmt->bindParam(1, $permissao->isParaCriar());
            $stmt->bindParam(2, $permissao->isParaEditar());
            $stmt->bindParam(3, $permissao->isParaExcluir());
            $stmt->bindParam(4, $permissao->isParaPublicar());
            $stmt->bindParam(5, $permissao->isParaDespublicar());

            $stmt->execute();

            return $this->conexao_mysql->lastInsertId();
        } catch (Exception $e) {
            return "erro";
        }
    }

    public function update($permissao) {
        
    }

    public function delete($permissao) {
        Try {
            $delete_sql = "DELETE FROM PERMISSAO WHERE ID_PERMISSAO = ?;";

            $stmt = $this->conexao_mysql->prepare($delete_sql);
            $stmt->execute(array($permissao->getIdPermissao()));
            return "sucess";
        } catch (Exception $e) {
            return "erro";
        }
    }

}

?>